package net.yla.smartbus.core.config;

import net.yla.smartbus.core.asp.LoginUserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author ZengXiaoLiang
 **/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

  @Autowired
  private LoginUserInterceptor loginUserInterceptor;


  /**
   * http访问获取访问图片的ip+端口
   * http://192.168.0.86:8686
   */
  @Value("${server.path}")
  private String httpIpPortStr;


  /**
   * chart统计图片原保存地址
   * E:\WenZhou\chartImages\
   */
  @Value("${save.path}")
  private String rootChartSavePath;

  /**
   * chart统计图映射地址 如: /chartImages/
   */
  @Value("${visit.path}")
  private String rootChartHttpPath;

  /**
   * 接口拦截
   * @param registry
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    super.addInterceptors(registry);
    // TODO 请求拦截
    registry.addInterceptor(loginUserInterceptor).addPathPatterns("/**").excludePathPatterns("/pub/**","/swagger-resources/**","/app/login"
   ,"/client/login","/app/sendSms/**","/bus/**","/client/login","/pub/erp/**");
  }

  /*资源处理器*/
  ///H:\IdeaProjects\SmartBus\src\main\resources\images
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
//    registry.addResourceHandler("/css/**").addResourceLocations("/WEB-INF/"+"/css/");
//    registry.addResourceHandler("/js/**").addResourceLocations("/WEB-INF/"+"/js/");
//    registry.addResourceHandler("/static/images/**").addResourceLocations("/WEB-INF/"+ "/static/images/");
    registry.addResourceHandler(" /static/**").addResourceLocations("classpath:/static/");
    //图片上传映射路径
//    registry.addResourceHandler("/static/picture/**").addResourceLocations("file:G:/picture/");

  }

}